package com.example.home.fragment.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.home.R;
import com.example.home.fragment.bean.RecommendListBean;

import java.util.List;

import static com.example.home.tool.StaticActi.ip;

public class RecommendListAdapter extends RecyclerView.Adapter<RecommendListAdapter.MyHoldy> {
    private Context context;
    private List<RecommendListBean.RowsBean> list;

    public RecommendListAdapter(Context context, List<RecommendListBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public RecommendListAdapter.MyHoldy onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_recom, null);
        return new RecommendListAdapter.MyHoldy(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyHoldy holder, int position) {
        Glide.with(context).load(ip+list.get(position).getCover()).into(holder.imgUrl);
        holder.readNum.setText(list.get(position).getReadNum()+"人看过");
        holder.title.setText(list.get(position).getTitle());
    }


    @Override
    public int getItemCount() {
        return list == null ? 0 : 3;
    }

    public class MyHoldy extends RecyclerView.ViewHolder {
        private ImageView imgUrl;
        private TextView title;
        private TextView readNum;




        public MyHoldy(@NonNull View itemView) {
            super(itemView);
            imgUrl = itemView.findViewById(R.id.imgUrl);
            title = itemView.findViewById(R.id.title);
            readNum = itemView.findViewById(R.id.readNum);
        }
    }
}
